package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.Result;
import com.ruoyi.product.response.MallProductReviewResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.MallProductReviewInfo;
import com.ruoyi.product.service.IMallProductReviewInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品评价Controller
 * 
 * @author ruoyi
 * @date 2025-08-03
 */
@RestController
@RequestMapping("/review")
public class MallProductReviewInfoController extends BaseController
{
    @Autowired
    private IMallProductReviewInfoService mallProductReviewInfoService;

    /**
     * 查询商品评价列表
     */
    @RequiresPermissions("product:review:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(MallProductReviewResponse mallProductReviewResponse)
    {
        startPage();
        List<MallProductReviewResponse> list = mallProductReviewInfoService.selectMallProductReviewInfoList(mallProductReviewResponse);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @RequiresPermissions("product:review:export")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductReviewResponse mallProductReviewResponse)
    {
        List<MallProductReviewResponse> list = mallProductReviewInfoService.selectMallProductReviewInfoList(mallProductReviewResponse);
        ExcelUtil<MallProductReviewResponse> util = new ExcelUtil<MallProductReviewResponse>(MallProductReviewResponse.class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @RequiresPermissions("product:review:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") String id)
    {
        return success(mallProductReviewInfoService.selectMallProductReviewInfoById(id));
    }

    /**
     * 新增商品评价
     */
    @RequiresPermissions("product:review:add")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductReviewInfo mallProductReviewInfo)
    {
        return toAjax(mallProductReviewInfoService.insertMallProductReviewInfo(mallProductReviewInfo));
    }

    /**
     * 修改商品评价
     */
    @RequiresPermissions("product:review:edit")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductReviewInfo mallProductReviewInfo)
    {
        return toAjax(mallProductReviewInfoService.updateMallProductReviewInfo(mallProductReviewInfo));
    }

    /**
     * 删除商品评价
     */
    @RequiresPermissions("product:review:remove")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable String[] ids)
    {
        return toAjax(mallProductReviewInfoService.deleteMallProductReviewInfoByIds(ids));
    }
}
